const getSourceBt1 = document.getElementById("getSourceBt1");
const VideoBt = document.getElementById("VideoBt")
function sendMessage(tabid) {//接收content的内容 主要的处理
  chrome.tabs.sendMessage(tabid, { action: "getText" }, function (respond) {
    var formatStr = respond.content;
    console.log(formatStr)
    chrome.tabs.create(//创建解析页面
      { url: formatStr },
    )

  })
}
BtJx = [
  {
    bt: document.getElementById("jx1Bt1"),
    jx: "https://jx.aidouer.net/?url="//解析
  },
  {
    bt: document.getElementById("jx1Bt2"),
    jx: "https://jx.quanmingjiexi.com/?url="
  },
  {
    bt: document.getElementById("jx1Bt3"),
    jx: "https://jx.bozrc.com:4433/player/analysis.php?v="
  },


]

if (BtJx[0].bt) {
  BtJx[0].bt.onclick = function () {
    openTab(BtJx[0].jx)
  }
}
if (BtJx[1].bt) {
  BtJx[1].bt.onclick = function () {
    openTab(BtJx[1].jx)
  }
}
if (BtJx[2].bt) {
  BtJx[2].bt.onclick = function () {
    openTab(BtJx[2].jx)
  }
}

function openTab(jxApi) {
  chrome.tabs.query(
    { active: true, currentWindow: true },
    function (tab) {
      var url = tab[0].url,
        title = tab[0].title,
        id = tab[0].id,
        jxUrl = jxApi + url;
      console.log(id, url, title)

      chrome.tabs.create(//创建解析页面
        { url: jxUrl },
      )
    });
}



if (getSourceBt1) {
  getSourceBt1.onclick = function () {
    chrome.tabs.query(
      { active: true, currentWindow: true },
      function (tab) {

        var url = tab[0].url,
          title = tab[0].title,
          id = tab[0].id;
        chrome.tabs.executeScript(id, { file: "content.js" }, function () {//发送message给content进行解析
          sendMessage(id)
        })
      })
  }
}

if (VideoBt) {
  VideoBt.onclick = function () {
    chrome.tabs.create(
      { url: "https://vip.diaoyu18.com/" },
    )
  }
}
